package com.common.groovy.action;

import cn.hutool.json.JSONObject;
import com.common.groovy.helper.GroovyHelper;
import com.common.groovy.model.ActionModel;
import com.common.groovy.model.DataModel;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component("CustomScript")
public class SimpleCustomAction implements IAction<JSONObject, Object> {

    @Autowired
    private GroovyHelper groovyHelper;

    @Override
    public Object execute(ActionModel actionDetail, DataModel data, JSONObject params) {
        //需要判断到底是增删改查的哪一种
        Object result = Strings.EMPTY;
        String shell = actionDetail.getShell();
        if (StringUtils.hasText(shell)) {
            result = groovyHelper.execute(shell, params);
        }
        return result;
    }
}
